<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
    <h1>回调页面 </h1>

</div>
</body>
<script type="text/javascript" src="script/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="js/vue/dist/vue.min.js"></script>
<script type="text/javascript" src="js/axios/dist/axios.js"></script>
<script type="text/javascript" src="js/commons.js"></script>
<script>
    new Vue({
        el:"#app",
        data:{

        },
        methods:{
            /*
                定义一个方法,把code回传到后台--->接受code 获取access_token
            */
            wxLogin(){
                let urlParam = parseParamObj(location.href);
                this.$http.get("/wxuser/wxlogin/"+urlParam.code).then(res=>{
                    if (res.data.success){
                        if(res.data.data.bindurl){//第一次登录,跳转到绑定页面
                            location.href=res.data.data.bindurl+"?code="+urlParam.code;
                        }else {//不是第一次登录
                            localStorage.setItem("token", res.data.data.token);
                            localStorage.setItem("user",JSON.stringify(res.data.data.user));
                            location.href="/index.html";
                        }
                    }else {
                        alert(res.data.message);
                    }
                })
            }

        },
        mounted(){
            this.wxLogin();
        }
    });
</script>
</html>